function needCLodop(){
    try{
	var ua=navigator.userAgent;
	if (ua.match(/Windows\sPhone/i) !=null) return true;
	if (ua.match(/iPhone|iPod/i) != null) return true;
	if (ua.match(/Android/i) != null) return true;
	if (ua.match(/Edge\D?\d+/i) != null) return true;
	
	var verTrident=ua.match(/Trident\D?\d+/i);
	var verIE=ua.match(/MSIE\D?\d+/i);
	var verOPR=ua.match(/OPR\D?\d+/i);
	var verFF=ua.match(/Firefox\D?\d+/i);
	var x64=ua.match(/x64/i);
	if ((verTrident==null)&&(verIE==null)&&(x64!==null)) 
		return true; else
	if ( verFF !== null) {
		verFF = verFF[0].match(/\d+/);
		if ((verFF[0]>= 42)||(x64!==null)) return true;
	} else 
	if ( verOPR !== null) {
		verOPR = verOPR[0].match(/\d+/);
		if ( verOPR[0] >= 32 ) return true;
	} else 
	if ((verTrident==null)&&(verIE==null)) {
		var verChrome=ua.match(/Chrome\D?\d+/i);		
		if ( verChrome !== null ) {
			verChrome = verChrome[0].match(/\d+/);
			if (verChrome[0]>=42) return true;
		};
	};
        return false;
    } catch(err) {return true;};
};

function cancel() {
	layer.closeAll();
};

//====页面引用CLodop云打印必须的JS文件：====
function initClodop(){
	var head = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
	var oscript = document.createElement("script");
	oscript.src ="http://127.0.0.1:8000/CLodopfuncs.js?priority=1";
	head.insertBefore( oscript,head.firstChild );

	//引用双端口(8000和18000）避免其中某个被占用：
	oscript = document.createElement("script");
	oscript.src ="http://127.0.0.1:18000/CLodopfuncs.js?priority=0";
	head.insertBefore( oscript,head.firstChild );
};
if(needCLodop()){
	initClodop();
};

dojo.declare(
		"_lodop_version",
		null,
		{

			// properties to be added to the class prototype

			currentVersion : "6.2.1.8",
			currentClodopVersion:"2.1.3.0",
			oOBJECTID : "MAIN_LODOP",
			oEMBEDID : "MAIN_LODOP_EM",
			msgContextID : "MAIN_printPageInfo_print",
			msgID : "MAIN_printPageInfo_msg_print",
			LODOP : null,
			// 自动创建的全局变量
			CreatedOKLodop : null,
			// initialization function
			constructor : function(args) {
				dojo.mixin(this,args);
			},

			// other functions
			getLodop : function() {
				/***************************************************************
				 * 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象： IE系列、IE内核系列的浏览器采用oOBJECT，
				 * 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
				 * 如果页面没有相关对象元素，则新建一个或使用上次那个,避免重复生成。
				 * 64位浏览器指向64位的安装程序install_lodop64.exe。
				 **************************************************************/
				// 返回值
				var rv = {};

				var strHtmInstall = "<br><font color='#909399'>打印控件未安装!点击这里<a href='"
						+ report_path
						+ "/unieap/pages/report/jsp/show/lodop/install/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
				var strHtmUpdate = "<br><font color='#909399'>打印控件需要升级!点击这里<a href='"
						+ report_path
						+ "/unieap/pages/report/jsp/show/lodop/install/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
				var strHtm64_Install = "<br><font color='#909399'>打印控件未安装!点击这里<a href='"
						+ report_path
						+ "/unieap/pages/report/jsp/show/lodop/install/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
				var strHtm64_Update = "<br><font color='#909399'>打印控件需要升级!点击这里<a href='"
						+ report_path
						+ "/unieap/pages/report/jsp/show/lodop/install/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
				var strHtmFireFox = "<br><br><font color='#909399'>（注意：如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它）</font>";
				var strHtmChrome = "<br><br><font color='#909399'>(如果此前正常，仅因浏览器升级或重安装而出问题，需重新执行以上安装）</font>";
				var strCLodopInstall32="<div style='margin-top: 16px;margin-left: 38px;font-size: 14px;'><font color='#909399'>32位操作系统<a href='"
						+ report_path
						+ "/unieap/pages/report/jsp/show/lodop/install/CLodop_Setup_for_Win32NT.exe' target='_self'>执行安装</a></font></div>";
				var strCLodopInstall64="<div style='margin-top: 16px;margin-left: 38px;font-size: 14px;'><font color='#909399'>  64位操作系统<a href='"
					+ report_path
					+ "/unieap/pages/report/jsp/show/lodop/install/CLodop_Setup_for_Win64NT.exe' target='_self'>执行安装</a></font></div></div>";
				var strCLodopUpdate32="<br><font color='#909399'>需要升级打印控件：32位操作系统<a href='"
					+ report_path
					+ "/unieap/pages/report/jsp/show/lodop/install/CLodop_Setup_for_Win32NT.exe' target='_self'>执行升级</a></font>";
				var strCLodopUpdate64="<font color='#909399'> 64位操作系统<a href='"
					+ report_path
					+ "/unieap/pages/report/jsp/show/lodop/install/CLodop_Setup_for_Win64NT.exe' target='_self'>执行升级</a></font>";
				var LODOP;
						try {
							// =====判断浏览器类型:===============
							var isIE = (navigator.userAgent.indexOf('MSIE') >= 0)
									|| (navigator.userAgent.indexOf('Trident') >= 0);
							if (needCLodop()) {
								try {
									LODOP = getCLodop();
								} catch (err) {
								}
								if (!LODOP&& document.readyState !== "complete") {
									alert("C-Lodop没准备好，请稍后再试！");
									return;
								}
								if (!LODOP) {
//									if (isIE)
//										document.write(strCLodopInstall32+strCLodopInstall64);
//									else
//										document.documentElement.innerHTML = strCLodopInstall32+strCLodopInstall64
//												+ document.documentElement.innerHTML;
									rv.doc =strCLodopInstall32+strCLodopInstall64;
									rv.LODOP = LODOP;
									this.LODOP = LODOP;
									return rv;
								} else {

									if (CLODOP.CVERSION < this.currentClodopVersion) {
//										if (isIE)
//											document.write(strCLodopUpdate32+strCLodopUpdate64);
//										else
//											document.documentElement.innerHTML = strCLodopUpdate32+strCLodopUpdate64
//													+ document.documentElement.innerHTML;
										rv.doc =strCLodopInstall32+strCLodopInstall64;
										rv.LODOP = LODOP;
										this.LODOP = LODOP;
										return rv;
									};
									var oEMBED = document
											.getElementById(this.oEMBEDID);
									var oOBJECT = document
											.getElementById(this.oOBJECTID);
									if (oEMBED && oEMBED.parentNode)
										oEMBED.parentNode.removeChild(oEMBED);
									if (oOBJECT && oOBJECT.parentNode)
										oOBJECT.parentNode.removeChild(oOBJECT);
									var divEMBED=document.getElementById("preview_MAIN_LODOP_div");
									if(divEMBED&& divEMBED.parentNode){
										divEMBED.parentNode.removeChild(divEMBED);
									}
								}
							} else {
								var is64IE = isIE
										&& (navigator.userAgent.indexOf('x64') >= 0);
								// =====如果页面有Lodop就直接使用，没有则新建:==========
								if (document.getElementById(this.oOBJECTID) != undefined
										|| document.getElementById(this.oEMBEDID) != undefined) {
									if (isIE) {
										LODOP = document
												.getElementById(this.oOBJECTID);
										this.LODOP = LODOP;
									} else {
										LODOP = document
												.getElementById(this.oEMBEDID);
										this.LODOP = document
												.getElementById(this.oEMBEDID);
									}
								} else {
									if (this.CreatedOKLodop == null) {
										LODOP = document
												.createElement("object");
										LODOP.setAttribute("width", 0);
										LODOP.setAttribute("height", 0);
										LODOP.setAttribute("style","position:absolute;left:0px;top:-100px;width:0px;height:0px;");
										if (isIE){
											LODOP.setAttribute("classid","clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
										}else{
											LODOP.setAttribute("type","application/x-print-lodop");
										}
										document.documentElement.appendChild(LODOP);
										this.CreatedOKLodop = LODOP;
									} else {
										LODOP = this.CreatedOKLodop;
										this.LODOP = LODOP;
									}
								}
								// =====判断Lodop插件是否安装过，没有安装或版本过低就提示下载安装:==========
								if ((LODOP == null)
										|| (typeof (LODOP.VERSION) == "undefined")) {
									if (navigator.userAgent.indexOf('Chrome') >= 0) {
										// document.documentElement.innerHTML=strHtmChrome+document.documentElement.innerHTML;
										rv.doc = strHtmChrome
												+ document.documentElement.innerHTML;
									} else if (navigator.userAgent
											.indexOf('Firefox') >= 0) {
										// document.documentElement.innerHTML=strHtmFireFox+document.documentElement.innerHTML;
										rv.doc = strHtmFireFox
												+ document.documentElement.innerHTML;
									}
									if (is64IE) {
										// document.write(strHtm64_Install);
										rv.doc = strHtm64_Install;
									} else if (isIE) {
										// document.write(strHtmInstall);
										rv.doc = strHtmInstall;
									} else {
										// document.documentElement.innerHTML=strHtmInstall+document.documentElement.innerHTML;
										rv.doc = strHtmInstall
												+ document.documentElement.innerHTML;
									}
									rv.LODOP = LODOP;
									this.LODOP = LODOP;
									return rv;
								}
								if (LODOP.VERSION < this.currentVersion) {
									if (is64IE) {
										// document.write(strHtm64_Update);
										rv.doc = strHtm64_Update;
									} else if (isIE) {
										// document.write(strHtmUpdate);
										rv.doc = strHtmUpdate;
									} else {
										// document.documentElement.innerHTML=strHtmUpdate+document.documentElement.innerHTML;
										rv.doc = strHtmUpdate
												+ document.documentElement.innerHTML;
									}
									rv.LODOP = LODOP;
									this.LODOP = LODOP;
									return rv;
								}
							}
							
							// =====如下空白位置适合调用统一功能(如注册码、语言选择等):====
							LODOP.SET_LICENSES("东软集团股份有限公司",
									"567418B7AB0D48BA46D8D05CDD2CDD47", "", "");
							// ============================================================
							LODOP.PRINT_INIT("UNIEAP Report");
							rv.LODOP = LODOP;
							this.LODOP = LODOP;
							return rv;
						} catch (err) {
					if (is64IE) {
						// document.documentElement.innerHTML="Error:"+strHtm64_Install+document.documentElement.innerHTML;
						rv.doc = "Error:" + strHtm64_Install
								+ document.documentElement.innerHTML;
					} else {
						// document.documentElement.innerHTML="Error:"+strHtmInstall+document.documentElement.innerHTML;
						rv.doc = "Error:" + strHtmInstall
								+ document.documentElement.innerHTML;
					}
					LODOP.PRINT_INIT("UNIEAP Report");
					rv.LODOP = LODOP;
					this.LODOP = LODOP;
					return rv;
				}
			},
			checking : function(rv) {
				if (rv) {
					var prex = "<div style='padding-left: 24px;padding-top: 24px;'><div class='info-class' style='height: 22px;'><div style='margin-left: 38px;font-size: 16px;color: #303133;font-weight: bold;'>打印控件未安装</div></div>";
					var aux = "<div style='padding-right: 24px;float: right;padding-top: 24px;'><button class='concel-button-class' onClick='cancel()'>关闭</button></div>"
					if (rv.doc) {
						layer.open({
							type: 1,
							title: false,
							closeBtn: 0,
						    area: ['400px', '190px'],
						    shadeClose: false, //点击遮罩关闭
						    content: prex + rv.doc + aux
						});
//						document.getElementById(this.msgContextID).style.display = "block";
//						document.getElementById(this.msgID).innerHTML = rv.doc;
						return false;
					} else {
						document.getElementById(this.msgContextID).style.display = "none";
					}
					if (!rv.LODOP) {
						return false;
					}
					return true;
				}
				return false;
			},
			
			getPrintData:function (_npage,dataContext){
				var printString ="";
				printString=printString+"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\">";
//				printString=printString+"<html>";
				printString=printString+"<head>";
				printString=printString+"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />";
				printString=printString+"<title>unieap Report</title>";
				printString=printString+"</head>";
				
				// add justify style
				(function() { 
					printString+="<style type='text/css'>\n";
					printString+=".justified_text {text-align:justify !important;text-justify:distribute-all-lines;text-align-last:justify;-moz-text-align-last:justify;-webkit-text-align-last:justify;}\n";
					printString+="@media screen and (-webkit-min-device-pixel-ratio:0){/* chrome*/.justified_text:after{content:\".\";display: inline-block;width:100%;overflow:hidden;height:0;}}\n";
					printString+="</style>\n";
				})();
				
				if(dataContext.style){
					printString=printString+"<style type='text/css'> ";
					for(var o in dataContext.style){
						printString = printString+dataContext.style[o]+" ";
					}  
					printString = printString+" </style> ";
				}
				if(!(dataContext.body==""||dataContext.body==null)){
				printString=printString+"<body ";
				printString=printString+" style =" +
				dataContext.body.style+
						">";
				}else{
					printString=printString+"<body style='background-color: white'>";
				}
				
				if(!(dataContext.backgroundImg==""||dataContext.backgroundImg==null)){
					printString=printString+dataContext.backgroundImg.img;
				}	
				
				printString = printString+dataContext.context[_npage-1];
				printString = printString+"</body>";
				printString = printString+"</html>";
				return printString;
			}
			
		});


//======================================//
//关于Cookie的操作
//======================================//

/**
* 设置Cookie
* 
* @param name
*            cookie名称
* @param value
*            cookie值
*/

function setcookieTopMarginOffset(value) {
	delCookie("cookieTopMarginOffset")
	setCookie("cookieTopMarginOffset",value);
}
function setcookieLeftMarginOffset(value) {
	delCookie("cookieLeftMarginOffset");
	setCookie("cookieLeftMarginOffset",value);
}

function setCookie(name, value) {
	var days = 30;
	var exp = new Date();
	exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
	document.cookie = name + "=" + escape(value) + ";expires="
			+ exp.toGMTString();
}
/**
* 获取Cookie
* 
* @param name
*            cookie名称
* @returns cookie值或null
*/
function getCookie(name) {
	var arr = document.cookie
			.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
	if (arr != null)
		return unescape(arr[2]);
	return null
}
/**
* 删除Cookie
* 
* @param name
*/
function delCookie(name) {
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval = getCookie(name);
	if (cval != null)
		document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}



//==================================================================================================
//var CreatedOKLodop7766=null;

//function __getLodop(oOBJECT,oEMBED){
///**************************
//  本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象：
//  IE系列、IE内核系列的浏览器采用oOBJECT，
//  其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
//  如果页面没有相关对象元素，则新建一个或使用上次那个,避免重复生成。
//  64位浏览器指向64位的安装程序install_lodop64.exe。
//**************************/
//        var strHtmInstall="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
//        var strHtmUpdate="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
//        var strHtm64_Install="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
//        var strHtm64_Update="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
//        var strHtmFireFox="<br><br><font color='#FF00FF'>（注意：如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它）</font>";
//        var strHtmChrome="<br><br><font color='#FF00FF'>(如果此前正常，仅因浏览器升级或重安装而出问题，需重新执行以上安装）</font>";
//        var strCLodopInstall32="<br><font color='#FF00FF'>打印控件未安装!32位操作系统请点击这里<a href='CLodop_Setup_for_Win32NT.exe' target='_self'>执行升级</a>,升级后请刷新页面。</font>";
//        var strCLodopInstall64="<br><font color='#FF00FF'>打印控件未安装!64位操作系统请点击这里<a href='CLodop_Setup_for_Win64NT.exe' target='_self'>执行升级</a>,升级后请刷新页面。</font>";
//        var strCLodopUpdate32="<br><font color='#FF00FF'>CLodop需升级!32位操作系统请点击这里<a href='CLodop_Setup_for_Win32NT.exe' target='_self'>执行升级</a>,升级后请刷新页面。</font>";
//        var strCLodopUpdate64="<br><font color='#FF00FF'>CLodop需升级!64位操作系统请点击这里<a href='CLodop_Setup_for_Win64NT.exe' target='_self'>执行升级</a>,升级后请刷新页面。</font>";
//        var LODOP;		
//	try{	
//	     //=====判断浏览器类型:===============
//	     var isIE	 = (navigator.userAgent.indexOf('MSIE')>=0) || (navigator.userAgent.indexOf('Trident')>=0);
//	     var is64IE  = isIE && (navigator.userAgent.indexOf('x64')>=0);
//	     //=====如果页面有Lodop就直接使用，没有则新建:==========
//	     if (oOBJECT!=undefined || oEMBED!=undefined) { 
//               	 if (isIE) 
//	             LODOP=oOBJECT; 
//	         else 
//	             LODOP=oEMBED;
//	     } else { 
//		 if (CreatedOKLodop7766==null){
//          	     LODOP=document.createElement("object"); 
//		     LODOP.setAttribute("width",0); 
//                     LODOP.setAttribute("height",0); 
//		     LODOP.setAttribute("style","position:absolute;left:0px;top:-100px;width:0px;height:0px;");  		     
//                     if (isIE) LODOP.setAttribute("classid","clsid:2105C259-1E0C-4534-8141-A753534CB4CA"); 
//		     else LODOP.setAttribute("type","application/x-print-lodop");
//		     document.documentElement.appendChild(LODOP); 
//	             CreatedOKLodop7766=LODOP;		     
// 	         } else 
//                     LODOP=CreatedOKLodop7766;
//	     };
//	     //=====判断Lodop插件是否安装过，没有安装或版本过低就提示下载安装:==========
//	     if ((LODOP==null)||(typeof(LODOP.VERSION)=="undefined")) {
//	             if (navigator.userAgent.indexOf('Chrome')>=0)
//	                 document.documentElement.innerHTML=strHtmChrome+document.documentElement.innerHTML;
//	             if (navigator.userAgent.indexOf('Firefox')>=0)
//	                 document.documentElement.innerHTML=strHtmFireFox+document.documentElement.innerHTML;
//	             if (is64IE) document.write(strHtm64_Install); else
//	             if (isIE)   document.write(strHtmInstall);    else
//	                 document.documentElement.innerHTML=strHtmInstall+document.documentElement.innerHTML;
//	    	     //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====	     
//	             LODOP.SET_LICENSES("东软集团股份有限公司","567418B7AB0D48BA46D8D05CDD2CDD47","","");
//	    	     //============================================================	  
//	             return LODOP;
//	     } else 
//	     if (LODOP.VERSION<"6.1.7.5") {
//	             if (is64IE) document.write(strHtm64_Update); else
//	             if (isIE) document.write(strHtmUpdate); else
//	             document.documentElement.innerHTML=strHtmUpdate+document.documentElement.innerHTML;
//	    	     //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====	     
//	             LODOP.SET_LICENSES("东软集团股份有限公司","567418B7AB0D48BA46D8D05CDD2CDD47","","");
//	    	     //============================================================	  
//	    	     return LODOP;
//	     };
//	     //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====	
//	     LODOP.SET_LICENSES("东软集团股份有限公司","567418B7AB0D48BA46D8D05CDD2CDD47","","");
//
//	     //============================================================	     
//	     return LODOP; 
//	} catch(err) {
//	     if (is64IE)	
//            document.documentElement.innerHTML="Error:"+strHtm64_Install+document.documentElement.innerHTML;else
//            document.documentElement.innerHTML="Error:"+strHtmInstall+document.documentElement.innerHTML;
//	     //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====	     
//	     LODOP.SET_LICENSES("东软集团股份有限公司","567418B7AB0D48BA46D8D05CDD2CDD47","","");
//	     //============================================================	  
//	     return LODOP; 
//	};
//}
